package com.example.healing.controller;

import com.example.healing.common.lang.Result;
import com.example.healing.entity.SongLike;
import com.example.healing.service.SongLikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author neymar
 * @date 2021年11月30日 15:40
 */
@EnableSwagger2
@RestController
@Api(tags = "喜欢与否")
@RequestMapping("/songlike")
public class SongLikeController {

    @Autowired
    private SongLikeService songLikeService;

    /**
     * @author neymar
     * @date 2021/12/1 21:49
     * @param songLike
     * @return com.example.healing.common.lang.Result
     * @description 增加 赞/踩
     */
    @RequiresAuthentication
    @ApiOperation(value = "增加 赞/踩（需要带token）")
    @PostMapping("")
    public Result create(@RequestBody @ApiParam("赞/踩 信息") SongLike songLike) {
        return songLikeService.create(songLike);
    }

    /**
     * @author neymar
     * @date 2021/12/1 21:49
     * @param songLike
     * @return com.example.healing.common.lang.Result
     * @description 取消 赞/踩
     */
    @RequiresAuthentication
    @ApiOperation(value = "取消 赞/踩（需要带token）")
    @DeleteMapping("")
    public Result delete(@Validated @RequestBody @ApiParam("赞/踩 信息") SongLike songLike) {
        return songLikeService.delete(songLike);
    }

    /**
     * @author neymar
     * @date 2021/12/1 21:49
     * @param uid
     * @param songId
     * @return com.example.healing.common.lang.Result
     * @description 获取用户对歌曲的 赞/踩
     */
    @RequiresAuthentication
    @ApiOperation(value = "获取用户对歌曲的 赞/踩（需要带token）")
    @GetMapping("/{uid}/{songId}")
    public Result getSongList(@ApiParam("用户id") @PathVariable("uid") String uid, @ApiParam("歌曲id") @PathVariable("songId") String songId) {
        return songLikeService.getLike(uid,songId);
    }
}
